package com.leetcode.LC;

import java.util.Arrays;

public class LC414 {
    public int thirdMax(int[] nums) {

        Arrays.sort(nums);
        int count = 1;
        if (nums.length >= 3) {
            for (int i = nums.length - 1; i > 0; i--) {
                if (nums[i] != nums[i - 1]) {
                    count++;
                    if (count == 3) {
                        return nums[i - 1];
                    }
                }
            }
            return nums[nums.length - 1];
        } else {
            return nums[nums.length - 1];
        }
    }

    public static void main(String[] args) {
        System.out.println(new LC414().thirdMax(new int[]{2, 2, 3,3}));
    }
}
